﻿using BCCommon;
using BCDto.WeChatComponent.WeChatMediaRecord;
using BCDto.WeChatComponent.WeChatNewsMaterialArticleRecord;
using BCService.WeChatComponent.WeChatNewsMaterialArticleRecordService;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.Management.WeChat
{
    /// <summary>
    /// 微信图文控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class WeChatNewsController : ManagementBaseController
    {
        private readonly IWeChatNewsMaterialArticleRecordService weChatNewsMaterialArticleRecordService;

        public WeChatNewsController(IWeChatNewsMaterialArticleRecordService weChatNewsMaterialArticleRecordService)
        {
            this.weChatNewsMaterialArticleRecordService = weChatNewsMaterialArticleRecordService;
        }

        /// <summary>
        /// 添加微信图文信息。
        /// </summary>
        /// <param name="weChatNewsMaterialArticleRecordRequestDtos">微信图文文章内容列表</param>
        /// <response code="201">已添加成功的微信图文文章信息。</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(WeChatMediaRecordDto), 201)]
        public IActionResult Post([FromBody]WeChatNewsMaterialArticleRecordRequestDto[] weChatNewsMaterialArticleRecordRequestDtos)
        {
            WeChatMediaRecordDto result = this.weChatNewsMaterialArticleRecordService.Add(weChatNewsMaterialArticleRecordRequestDtos);
            return this.Created(string.Format("/api/v1/sim/WeChatNews/{0}", result.MediaId), result);
        }
        /// <summary>
        /// 修改微信图文信息。
        /// </summary>
        /// <param name="mediaId">素材Id</param>
        /// <param name="weChatNewsMaterialArticleRecordPutDtos">微信图文文章内容修改列表</param>
        /// <response code="200">已修改成功的微信图文文章信息。</response>
        /// <returns></returns>
        [HttpPut("{media_id}")]
        [ProducesResponseType(typeof(WeChatMediaRecordDto), 200)]
        public IActionResult Put([FromRoute(Name ="media_id")]string mediaId,[FromBody]WeChatNewsMaterialArticleRecordPutDto[] weChatNewsMaterialArticleRecordPutDtos)
        {
            return this.Ok(this.weChatNewsMaterialArticleRecordService.Update(mediaId,weChatNewsMaterialArticleRecordPutDtos));
        }
        /// <summary>
        /// 删除微信图文素材。
        /// </summary>
        /// <param name="mediaId">素材id</param>
        /// <response code="204">无内容。</response>
        /// <returns></returns>
        [HttpDelete("{media_id}")]
        public IActionResult Delete([FromRoute(Name = "media_id")]string mediaId)
        {
            this.weChatNewsMaterialArticleRecordService.Delete(mediaId);
            return this.NoContent();
        }
        /// <summary>
        /// 获取微信图文列表。
        /// </summary>
        /// <param name="mediaId">素材id</param>
        /// <param name="title">文章标题</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ascending">排序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取微信自定义菜单列表。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<WeChatMediaRecordDto>), 200)]
        public IActionResult Get([FromQuery(Name = "media_id")]string mediaId,
            [FromQuery(Name ="title")]string title,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int pageIndex=1,
            [FromQuery(Name = "size")]int pageSize=20)
        {
            return this.Ok(this.weChatNewsMaterialArticleRecordService.Get(mediaId,title, start,end,ascending,pageIndex,pageSize));
        }
    }
}
